﻿using ELF.Data;
using ELF.Infrastructure.Data.Interceptors;
using Interfaces;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace ELF.Modules;

[DependsOn(typeof(ELFIdGeneratorModule))]
[DependsOn(typeof(ELFDDDDomainModule))]
[DependsOn(typeof(ELFDDDInfrastructureModule))]
public class ELFDDDDataModule : BaseModule
{
    public override Task ConfigureServicesAsync(IHostApplicationBuilder builder)
    {
        IConfiguration configuration = builder.Configuration;
        var services = builder.Services;

        //Todo 这里有问题，加了两个拦截器但是用的同一个接口。
        services.AddScoped<ISaveChangesInterceptor, AuditableEntityInterceptor>();
        services.AddScoped<ISaveChangesInterceptor, DispatchDomainEventsInterceptor>();

        services.AddSingleton(TimeProvider.System);

        services.AddScoped(typeof(IRepository<,>), typeof(EFCoreRepository<,>));
        return base.ConfigureServicesAsync(builder);
    }
}
